<!DOCTYPE html>
<html lang="zh" xmlns:th="https://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('博客列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 博客概览
                </div>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新列表"><i
                            class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <ul class="folder-list m-b-md linksDetails" style="padding: 0">
                    <li class="condition">
                        <a> <i class="fa fa-inbox "></i> 所有
                            <span class="label label-success pull-right"
                                  th:text="${total}">123 </span>
                        </a>
                    </li>
                    <li class="condition" val="1">
                        <a> <i class="fa fa-tags "></i> 已发布
                            <span class="label  label-default  pull-right "
                                  th:text="${published}">123</span>
                        </a>
                    </li>
                    <li class="condition" val="2">
                        <a> <i class="fa fa-chain-broken "></i> 草稿箱
                            <span class="label label-warning pull-right " th:text="${draft}">123</span>
                        </a>
                    </li>
                    <li class=" condition" val="3">
                        <a> <i class="fa fa-indent "></i> 垃圾箱
                            <span class="label label-danger  pull-right "
                                  th:text="${garbage}"> 123</span>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="blog-form">
                <input type="hidden" id="parentId" name="parentId">
                <div class="select-list">
                    <ul>
                        <li>
                            博客标题：<input type="text" name="title"/>
                        </li>
                        <li>
                            博客状态：<select id="blogStatus" name="status"
                                         th:with="type=${@dict.getType('blog_blog_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            推荐：<select id="blogSupport" name="support"
                                       th:with="type=${@dict.getType('blog_blog_support')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i> 搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i> 重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="createMenuItem('/blog/blog/add','新增博文')">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary btn-edit single disabled" onclick="$.operate.editTab()">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del multiple disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-primary btn-del  multiple  disabled" onclick="changeStatus(1)">
                <i class="fa fa-list-ol"></i> 发布
            </a>
            <a class="btn btn-warning btn-del multiple disabled" onclick="changeStatus(2)">
                <i class="fa fa-strikethrough"></i> 草稿箱
            </a>
            <a class="btn btn-danger btn-del multiple disabled" onclick="changeStatus(3)">
                <i class="fa fa-trash"></i> 垃圾箱
            </a>
            <a class="btn btn-default btn-del multiple disabled" onclick="pushBaidu()">
                <i class="fa fa-exchange"></i> 推送到百度
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<script th:inline="javascript">
    var datas = [[${@dict.getType('blog_blog_status')}]];
    var support = [[${@dict.getType('blog_blog_support')}]];
    var prefix = ctx + "blog/blog";

    function changeStatus(status) {
        var data = {"blogIds": $.table.getSelectIds()};
        $.operate.put($.table._option.changeStatusUrl + "/" + status, data);
    }

    function changeAllowComment(blogId) {
        $.operate.put($.table._option.changeAllowCommentUrl + "/" + blogId, data);
    }

    $(".condition").click(function () {
        $("#blogStatus").val($(this).attr("val"));
        $.table.search();
    });

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});

        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            changeStatusUrl: prefix + "/status",
            changeSupportUrl: prefix + "/support",
            changeAllowCommentUrl: prefix + "/allowComment",
            sortName: "createTime",
            sortOrder: "desc",
            uniqueId: "blogId",
            modalName: "博客",
            columns: [{
                field: 'state',
                checkbox: true
            }, {
                field: 'blogId',
                title: '博客ID'
            }, {
                field: 'title',
                title: '博客标题',
                formatter: function (value, row, index) {
                    return $.table.tooltip(value);
                }
            }, {
                field: 'createTime',
                title: '创建时间',
                sortable: true
            }, {
                field: 'status',
                title: '状态',
                formatter: function (value, row, index) {
                    return $.table.selectDictLabel(datas, value);
                }
            }, {
                field: 'support',
                title: '推荐',
                align: 'center',
                formatter: function (value, row, index) {
                    return statusTools(value, row);
                }
            }, {
                field: 'allowComment',
                title: '评论',
                align: 'center',
                formatter: function (value, row, index) {
                    return statusToolsAllowComment(value, row);
                }
            }, {
                field: 'weight',
                title: '权重',
                align: 'center',
            }, {
                field: 'click',
                title: '点击量',
                sortable: true
            }, {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.blogId + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                    actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.blogId + '\')"><i class="fa fa-remove"></i> 删除</a> ');
                    actions.push('<a class="btn btn-info btn-xs ' + '" href="javascript:void(0)" onclick="detail(\'' + row.blogId + '\')"><i class="fa fa-search"></i> 详细</a> ');
                    return actions.join('');
                }
            }]
        };
        $.table.init(options);
    });

    function statusTools(value, row) {
        if (value == "0") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.blogId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.blogId + '\')"></i> ';
        }
    }

    function statusToolsAllowComment(value, row) {
        if (value == false) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableAllowComment(\'' + row.blogId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableAllowComment(\'' + row.blogId + '\')"></i> ';
        }
    }

    /* 博客禁止评论评论 */
    function disableAllowComment(blogId) {
        $.modal.confirm("确认要禁止评论该博文吗？", function () {
            $.operate.put($.table._option.changeAllowCommentUrl + "/" + blogId + "/" + false);
        })
    }

    /* 博客允许评论 */
    function enableAllowComment(blogId) {
        $.modal.confirm("确认要允许评论该博文吗？", function () {
            $.operate.put($.table._option.changeAllowCommentUrl + "/" + blogId + "/" + true);
        })
    }

    /* 博客推荐-停用 */
    function disable(blogId) {
        $.modal.confirm("确认要取消推荐该博文吗？", function () {
            $.operate.put($.table._option.changeSupportUrl + "/0", {"blogId": blogId});
        })
    }

    /* 博客推荐-启用 */
    function enable(blogId) {
        $.modal.confirm("确认要推荐该博文吗？", function () {
            $.operate.put($.table._option.changeSupportUrl + "/1", {"blogId": blogId});
        })
    }

    function detail(id) {
        var title = "详细";
        var url = "/f/article/" + id + '.html';
        var width = $(window).width() / 1.5;
        var height = $(window).height() / 1.2;
        //如果是移动端，就使用自适应大小弹窗
        if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
            width = 'auto';
            height = 'auto';
        }
        if ($.common.isEmpty(title)) {
            title = false;
        }
        if ($.common.isEmpty(url)) {
            url = "/404.html";
        }
        if ($.common.isEmpty(width)) {
            width = 800;
        }
        if ($.common.isEmpty(height)) {
            height = ($(window).height() - 50);
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "详细",
            content: url,
            btn: '关闭',
            // 弹层外区域关闭
            shadeClose: true,
            success: function (layer) {
                layer[0].childNodes[3].childNodes[0].attributes[0].value = 'layui-layer-btn1';
            },
            btn1: function (index) {
                layer.close(index);
            }
        });
    }
</script>
</body>

</html>